home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / tapemesr / source / tapetest.sx < prev   
Encoding:
Text File  |  1996-05-21  |  5.7 KB  |  174 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. --*=============================================================================*
  3. --* Filename: tapetest.sx
  4. --*
  5. --* Other Files Required: interfac.sxl
  6. --*
  7. --* Purpose: Test the updated tape measure accessory.  Run this to create the
  8. --*          tapetest.sxt file.  Then run that file to test the tape measure.
  9. --*
  10. --* Author: Robert Lockstone : 12-15-95
  11. --*=============================================================================*
  12.  
  13. --*=============================================================================*
  14. --* Get the accessory interface module.
  15. --*=============================================================================*
  16. if ((getModule @AccessoryInterface) = false) do
  17.    (
  18.    open LibraryContainer dir:(parentDir theScriptDir) \
  19.                          path:"interfac.sxl"
  20.    )
  21.  
  22. module TapeTest
  23.    uses ScriptX
  24.    uses AccessoryInterface --Use the accessory interface defined in interfac.sxl
  25. end
  26.  
  27. in module TapeTest
  28.  
  29. class TapeTitle (TitleContainer)
  30.    instance variables
  31.       currentScene
  32. end
  33.  
  34. method afterInit self {class TapeTitle} #rest args ->
  35.    (
  36.    apply nextMethod self args
  37.    
  38.    local w  := new Window fill:whiteBrush
  39.    w.name   := "Tape Measure Test"
  40.    w.title  := self
  41.    
  42.    local str := "Use 'Open Accessory' from the File menu and look for tape.sxa."
  43.    local txt := new TextPresenter boundary:(new Rect x2:400 y2:50) \
  44.                                   target:str
  45.    txt.position := new Point x:10 y:75
  46.    prepend w txt
  47.    
  48.    self.name         := "Tape Measure Test"
  49.    self.currentScene := w
  50.  
  51.    append self.windows w
  52.    )
  53.  
  54. --*=============================================================================*
  55. --* Method to check if an accessory is appropriate for this title.  It must
  56. --* answer the following questions:
  57. --*
  58. --*    @question1 --Do you want to add yourself to me?
  59. --*    @question2 --Do you inherit from TwoDPresenter, i.e. can you be appended
  60. --*                 to a window?
  61. --*=============================================================================*
  62. method isAppropriateAccessory self {class TapeTitle} acc ->
  63.    (
  64.    local answer := false
  65.  
  66.    if (isDefined accessoryAnswersGetter) and \
  67.       (canObjectDo acc accessoryAnswersGetter) do
  68.       (
  69.       if ((getOne acc.accessoryAnswers @question1) = @yes) then
  70.          (
  71.          answer := true
  72.          )
  73.       else
  74.          (
  75.          if ((getOne acc.accessoryAnswers @question2) = @yes) do
  76.             (
  77.             answer := true
  78.             )
  79.          )
  80.       )
  81.    
  82.    return answer
  83.    )
  84.  
  85. --*=============================================================================*
  86. --* Overridden method to get and add a generic accessory to a scene.
  87. --*
  88. --* (Note: This will not work for the tape measure accessory because the tape
  89. --*        measure requires two items to be appended to the current scene, the
  90. --*        tape measure and its 'display' instance variable.  Also, the tape 
  91. --*        measure requires that the method updateScale be called on it after 
  92. --*        it has been appended to the current scene.  But that is too specific
  93. --*        for this general addAccessory method.  That is why the tape measure
  94. --*        takes care of adding itself to a title.  See the tape measure
  95. --*        accessory container's startupAction IV defined in maketape.sx.
  96. --*=============================================================================*
  97. method addAccessory self {class TapeTitle} acc ->
  98.    (
  99.    if ((getOne acc.accessoryAnswers @question1) != @yes) do
  100.       (
  101.       local thisAcc := (getAccessories acc)[1]  --assume there is only one item
  102.        
  103.       --*======================================================================*
  104.       --* You could put additional code in here to check the various 
  105.       --* answers in the accessoryAnswers IV of the AccessoryContainer,
  106.       --* and decide what to do with the accessory based on those answers.
  107.       --*
  108.       --* I am going to get check to see if the accessory can do an addToTitle.
  109.       --* If it can't, then I'll check to see if it's a presenter, and add it
  110.       --* it myself.
  111.       --*======================================================================*
  112.        
  113.       if (canObjectDo thisAcc addToTitle) then
  114.          (
  115.          addToTitle thisAcc pres:self.currentScene
  116.          )
  117.       else
  118.          (
  119.          if ((getOne acc.accessoryAnswers @question2) = @yes) do
  120.             (
  121.             prepend self.currentScene thisAcc
  122.             )
  123.          )
  124.       )
  125.  
  126.    nextMethod self acc
  127.    )
  128.  
  129. -- Method importTool opens a file dialog to import the tape measure.
  130. -- (Note: stolen from AutoFinder.sx)
  131. method importTool self {class TapeTitle} ->
  132. (
  133.     -- Open a file panel to import the tape measure.
  134.     local op := new OpenPanel
  135.     openFilePanel op
  136.     if (not op.validReply) do return
  137.     
  138.     -- Open the storage container and load the tape meaure accessory.
  139.     local fileName := op.filename[size op.fileName]
  140.     deleteLast op.fileName
  141.     local drep := spawn theRootDir op.fileName
  142.     local c := open AccessoryContainer dir:drep path:fileName
  143.     addAccessory self c
  144. )
  145.  
  146. -- Method initKeyboardWatch sets up an event receiver for keyboard events,
  147. -- restricting the key code to the character "i". When an "i" is keyed and the
  148. -- @command key modifier is active, the importTool method is invoked on the 
  149. -- stage manager.
  150. -- (Note: stolen from AutoFinder.sx)
  151. method initKeyboardWatch self {class TapeTitle} ->
  152. (
  153.     local kd
  154.     kd := new KeyboardDownEvent
  155.     kd.device := new KeyboardDevice
  156.     kd.eventReceiver := (arg interest ev ->
  157.         if (isMember ev.keyModifiers @control) do importTool self)
  158.     kd.maxKeyCode := 73
  159.     kd.minKeyCode := 73
  160.     addEventInterest  kd
  161. )
  162.  
  163. global tc := new TapeTitle dir:(parentDir theScriptDir) \
  164.                            path:"tapetest.sxt"
  165.  
  166. tc.startupAction := (tc -> show tc.currentScene)
  167.  
  168. append tc (getModule @TapeTest)
  169.  
  170. close tc
  171.  
  172. "Compiled tapetest.sx"
  173.  
  174. -->>>